package com.jdd.pedicure.controller;

import com.jdd.pedicure.entity.Item;
import com.jdd.pedicure.entity.Result;
import com.jdd.pedicure.entity.Staff;
import com.jdd.pedicure.service.StaffService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RequestMapping("staff")
@Controller
public class StaffController {
    @Resource
    StaffService staffservice;

    @RequestMapping("/gostaff")
    public String stafflist()
    {
        return "staff";
    }
    @RequestMapping("/goAdd")
    public String addAdmin(Integer id, HttpServletRequest request) {
        Staff byId = new Staff();
        if (id != null) {
            byId = staffservice.queryById(id);
        }
        request.setAttribute("edit", byId);
        return "staffAdd";
    }
    @RequestMapping("/delete")
    public Result<Item> delete(int id) {
        staffservice.delete(id);
        Result<Item> staffResult = new Result<>();
        staffResult.setCode("0");
        return staffResult;
    }

    @ResponseBody
    @RequestMapping("/save")
    public Result<Staff> save(@RequestBody Staff item) {
        staffservice.saveOrUpdate(item);
        Result<Staff> itemResult = new Result<>();
        itemResult.setCode("0");
        return itemResult;
    }
    @ResponseBody
    @RequestMapping("/deletes")
    public Result<Item> deletes(@RequestBody List<Staff> staffs) {
        staffservice.deletes(staffs);
        Result<Item> itemResult = new Result<>();
        itemResult.setCode("0");
        return itemResult;
    }
    @ResponseBody
    @RequestMapping("/stafflist")
    public Result<Staff> stafflist(Result<Staff> result,Staff example)
    {
        result.setExample(example);
        staffservice.queryByPage(result);
        result.setCode("0");
        return result;
    }
    @RequestMapping("getStaffId")
    @ResponseBody
    public Result<Staff> getStaffId(){
        Result staffResult=new Result();
        Staff staff=new Staff();
        staff.setStaffState("1");
        staffResult.setExample(staff);
        Result result = staffservice.queryAllfree(staffResult);
        result.setCode("0");
        return result;
    }
}
